package com.example.hadoopdemo.mapreduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author jianwang9@iflytek.com
 * @create 2018-04-02 10:27
 **/
public class MapreduceMapper extends Mapper<LongWritable,Text,Text,IntWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //获取一行数据
        String line = value.toString();

        //从数据中获取自己想要的数据,塞入到context中   这就是map操作

        String year = line.substring(10, 14);

        Integer temp = Integer.parseInt(line.substring(20, 25));

        context.write(new Text(year),new IntWritable(temp));
    }
}
